package com.tianhui.consignortwofei.widget;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.fgs.common.CommonDialog;
import com.fgs.common.utils.CommonUtil;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.enty.OrderInfo;
import com.tianhui.consignortwofei.pattern.freightCalculation.CalculationController;


/**
 * @author fgs
 * @date 2020/4/9
 * @description
 **/
public class PaymentDetailDialog extends CommonDialog {
    private TextView positiveTextView;
    private TextView negativeTextView;
    private TextView amountTextView;
    private TextView insurePriceTextView;
    private TextView messageServicePriceTextView;
    private TextView grantsTextView;
    private OrderInfo orderInfo;

    public PaymentDetailDialog(@NonNull Context context, OrderInfo orderInfo) {
        super(context, R.style.style_select_dialog);
        this.orderInfo = orderInfo;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_payment_detail);
        setCancelable(true);
        setCanceledOnTouchOutside(false);
        positiveTextView = findViewById(R.id.layout_operate_tip_dialog_positiveTextView);
        negativeTextView = findViewById(R.id.layout_operate_tip_dialog_negativeTextView);
        amountTextView = findViewById(R.id.dialog_payment_detail_amountTextView);
        insurePriceTextView = findViewById(R.id.dialog_payment_detail_insurePriceTextView);
        messageServicePriceTextView = findViewById(R.id.dialog_payment_detail_messageServicePriceTextView);
        grantsTextView = findViewById(R.id.dialog_payment_detail_grantsTextView);

        positiveTextView.setText("关闭");
        negativeTextView.setVisibility(View.GONE);

        amountTextView.setText(TextUtils.isEmpty(orderInfo.freightprice) == true ? "0" : orderInfo.freightprice);
        insurePriceTextView.setText("保险费用：" + (TextUtils.isEmpty(orderInfo.insureprice) == true ? "0" : orderInfo.insureprice) + " 元");
        String servicePrice = CommonUtil.keepTwoDecimal(
                CalculationController.getInstance().getServicePrice(
                        orderInfo,
                        orderInfo.grants,
                        orderInfo.otherpirce)
                        + ""
        );
        messageServicePriceTextView.setText("信息服务费：" + (TextUtils.isEmpty(servicePrice) == true ? "0" : servicePrice) + " 元");
        grantsTextView.setText("补助金：" + (TextUtils.isEmpty(orderInfo.grants) == true ? "0" : orderInfo.grants) + " 元");

        positiveTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

}
